//引入二次封装的 axios，axios 发送请求返回的结构是 Promise 对象
import requests from "./ajax";

//引入 mock 请求
import mockRequests from "./mockAjax";

//商品分类三级菜单接口 /api/product/getBaseCategoryList  GET 无参数
//对外暴露一个函数，只需要调用这个函数，就会向服务器发送 Ajax 请求，然后获取服务器返回的数据
export const reqGetCategoryList = () => requests.get("/product/getBaseCategoryList");

//获取 banner 图接口 /mock/banner
export const reqGetBannerList = () => mockRequests.get("/banner");

//获取 floor 楼层数据接口 /mock/floor
export const reqFloorList = () => mockRequests.get("/floor");

//获取搜索模块的数据，需要传递参数，axios 使用 data 接收
//注意：需要给服务器传递一个默认参数【至少是一个空对象 data】
export const reqGetSearchInfo = (params) => requests({
    url: "/list",
    method: "post",
    data: params,
});

//获取商品信息的接口
export const reqDetailInfo = (skuId) => requests({
    url: `/item/${skuId}`,
    method: "get",
});

//商品加入购物车/修改购物车商品的数量
export const reqAddOrUpdateCart = (skuId, skuNum) => requests({
    method: "post",
    url: `/cart/addToCart/${skuId}/${skuNum}`,
});

//查询购物车详情
export const reqShopCartList = () => requests({
    method: "get",
    url: `/cart/cartList`,
});

//删除购物车商品接口
export const reqDeleteShopCart = (skuId) => requests({
    method: "delete",
    url: `/cart/deleteCart/${skuId}`,
});

//修改商品的勾选状态
export const reqUpdateShopCartChecked = (skuId, isChecked) => requests({
    method: "get",
    url: `/cart/checkCart/${skuId}/${isChecked}`,
});